package com.technology.education.ui.common.goods

import androidx.lifecycle.MutableLiveData
import com.technology.education.data.model.ExchangeGoodsModel
import com.technology.education.data.model.GoodsList
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

/**
 *@author:create by BZY
 *Date: 2022/3/29 12
 */
class ConfirmGoodOrderViewModel : BaseViewModel() {
    val  result=MutableLiveData<ResultState<ExchangeGoodsModel>>()
    var info: GoodsList? = null
    var count = 1
    var city = ""
    var province = ""
    var district = ""
    var detail = ""
    var name = ""
    var phone = ""

    fun commitData() {
        if (name.isEmpty()) {
            toast("请输入收货人姓名")
            return
        }
        if (phone.isEmpty()) {
            toast("请输入收货人手机号")
            return
        }
        if (province.isEmpty()) {
            toast("请选择收货地址")
            return
        }
        if (detail.isEmpty()) {
            toast("请输入详细收货地址")
            return
        }
        request(
            {
                apiService.exchangePointGoods(
                    hashMapOf(
                        "name" to name,
                        "phone" to phone,
                        "address" to detail,
                        "city" to city,
                        "district" to district,
                        "province" to province,
                        "goodsId" to info?.id,
                        "number" to count
                    )
                )
            },result)
    }

}